package com.sky.controller.user;

import com.sky.dto.ShoppingCartItemDTO;
import com.sky.dto.ShoppingCartItemDTO;
import com.sky.entity.ShoppingCartItem;
import com.sky.entity.ShoppingCartItem;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api("C端-购物车相关接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车，但是用户每次添加商品时是逐项添加，传过来的参数是单个商品，所以添加整个购物车其实是一项一项dto添加")
    public Result addShoppingCart(@RequestBody ShoppingCartItemDTO shoppingCartItemDTO) {
        log.info("添加的购物车每一项是，{}",shoppingCartItemDTO);
        shoppingCartService.addShoppingCart(shoppingCartItemDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车,也就是查看商品项的list集合")
    public Result<List<ShoppingCartItem>> showShoppingCart(){
        log.info("查看购物车");
        List<ShoppingCartItem> list=shoppingCartService.showShoppingCart();
        return Result.success(list);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanShoppingCart(){
        log.info("清空购物车");
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
}
